package sg.edu.nus.iss.billing.vo.customer;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import sg.edu.nus.iss.billing.common.DbUtil;
import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.common.exception.InvalidParamsException;
import sg.edu.nus.iss.billing.vo.common.IDbSerialisable;

public class CustomerComplaintVO implements IDbSerialisable{

	public CustomerComplaintVO(){
		
	}
	
	public CustomerComplaintVO(String accountNo) {
		super();
		this.accountNo = accountNo;
	}
	
	private String complaintId;
	private String accountNo;
	private String complaint;
	private String status = Util.COMPLAINT_PENDING;
	private Date dateCreated;
	private Date dateModified;
//	private AccountVO accountVO;
	
//	/**
//	 * @return the accountVO
//	 */
//	public AccountVO getAccountVO() {
//		return accountVO;
//	}
//	/**
//	 * @param accountVO the accountVO to set
//	 */
//	public void setAccountVO(AccountVO accountVO) {
//		this.accountVO = accountVO;
//	}
	/**
	 * @return the complaintId
	 */
	public String getComplaintId() {
		return complaintId;
	}
	/**
	 * @param complaintId the complaintId to set
	 */
	public void setComplaintId(String complaintId) {
		this.complaintId = complaintId;
	}
	/**
	 * @return the accountNo
	 */
	public String getAccountNo() {
		return accountNo;
	}
	/**
	 * @param accountNo the accountNo to set
	 */
	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}
	/**
	 * @return the complaint
	 */
	public String getComplaint() {
		return complaint;
	}
	/**
	 * @param complaint the complaint to set
	 */
	public void setComplaint(String complaint) {
		this.complaint = complaint;
	}
	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	/**
	 * @return the dateCreated
	 */
	public Date getDateCreated() {
		return dateCreated;
	}
	/**
	 * @param dateCreated the dateCreated to set
	 */
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	/**
	 * @return the dateModified
	 */
	public Date getDateModified() {
		return dateModified;
	}
	/**
	 * @param dateModified the dateModified to set
	 */
	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}

	@Override
	public String serialised() {
		// accountNo^complaintId^Status^dateCreated^dateModified^complaint
		StringBuilder sb = new StringBuilder();
		sb.append(accountNo);
		sb.append(DbUtil.DELIMITER);
		sb.append(complaintId);
		sb.append(DbUtil.DELIMITER);
		sb.append(status);
		sb.append(DbUtil.DELIMITER);
		sb.append(Util.getFormattedDate(dateCreated));
		sb.append(DbUtil.DELIMITER);
		sb.append(Util.getFormattedDate(dateModified));
		sb.append(DbUtil.DELIMITER);
		sb.append(complaint);
		return sb.toString();
	}

	@Override
	public void setParameters(String serialisedEntry)
			throws InvalidParamsException {
		String[] tokens =  serialisedEntry.split(java.util.regex.Pattern.quote(DbUtil.DELIMITER));
		if (tokens.length != 6) {
			throw new InvalidParamsException("Expected 6 parameters, received " + tokens.length);
		}
		else {
			setAccountNo(tokens[0]);
			setComplaintId(tokens[1]);
			setStatus(tokens[2]);
			setDateCreated(Util.getDateFromString(tokens[3]));
			setDateModified(Util.getDateFromString(tokens[4]));
			setComplaint(tokens[5]);
		}
	}
}
